import {Service} from "adajs";
import {format} from './../../../lib/helper';

class NewsService extends Service {
    defaultData() {
        return {
            isLoad: false,
            newsInfo: {
                "lbDm": "qtsx",
                "zt": "全国老龄工作委员会关于深入开展2018年全国\u201c敬老月\u201d活动的通知",
                "nr": "",
                "fbfwbz": "",
                "isSignUp": "",
                "isRide": "1",
                "ztDm": 0,
                "crtUser": "admin",
                "crtTime": "2018-12-21 10:45:33",
                "crtIp": "127.0.0.1",
                "filesInfo": [],
                "id": "2aef96ea-4b77-4c2b-869b-d877672eabb4"
            },
            id: ""
        };
    }

    onupdate(current, id) {
        if (id) {
            return this.context.request.post("/api/lgb/app/lgb/noticeinfo/getInfo", {id}).then(({data}) => {
                current.id = id;
                current.isLoad = true;
                current.newsInfo = data;
                current.newsInfo.crtTime = format(new Date(data.crtTime.replace(/\-/g,"/")), 'yyyy-MM-dd');
            });
        }
    }
}

export default NewsService;